﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.CustomerServices;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    /// <summary>
    ///This is a test class for CustomerServiceRepositoryTest and is intended
    ///to contain all CustomerServiceRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CustomerServiceRepositoryTest : RepositoryTestsBase<CustomerService>
    {
       
       public override System.Linq.Expressions.Expression<Func<CustomerService, bool>> FilterExpression
        {
            get { return a => a.CustomerServiceId == TestConstants.Instance.CUSTOMER_SERVICE_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<CustomerService, Guid>> OrderByExpression
        {
            get { return a => a.CustomerServiceId; }
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindCustomerService_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerServiceRepository repository = new CustomerServiceRepository(context, traceManager);

            //Act
            repository.FindCustomerService(null);
        }

        #region CustomerServiceIdSpecification

        [TestMethod()]
        public void FindCustomerServiceById_Invoke_InvalidUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerServiceRepository repository = new CustomerServiceRepository(context, traceManager);

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            CustomerServiceIdSpecification spec = new CustomerServiceIdSpecification(invalidId);

            //Act
            CustomerService customer = repository.FindCustomerService(spec);

            //Assert
            Assert.IsNull(customer);
        }

        /// <summary>
        ///A test for FindCustomerService
        ///</summary>
        [TestMethod()]
        public void FindCustomerServiceById_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerServiceRepository repository = new CustomerServiceRepository(context, traceManager);

            CustomerServiceIdSpecification spec = new CustomerServiceIdSpecification(TestConstants.Instance.CUSTOMER_SERVICE_ID);

            //Act
            CustomerService customerService = repository.FindCustomerService(spec);

            //Assert
            Assert.IsNotNull(customerService);
        }

        #endregion

        #region CustomerServiceOrderIdSpecification

        [TestMethod()]
        public void FindCustomerServiceByOrderId_Invoke_InvalidUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerServiceRepository repository = new CustomerServiceRepository(context, traceManager);

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            CustomerServiceOrderIdSpecification spec = new CustomerServiceOrderIdSpecification(invalidId);

            //Act
            CustomerService customer = repository.FindCustomerService(spec);

            //Assert
            Assert.IsNull(customer);
        }
        
        /// <summary>
        ///A test for FindCustomerService
        ///</summary>
        [TestMethod()]
        public void FindCustomerServiceByOrderId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerServiceRepository repository = new CustomerServiceRepository(context, traceManager);

            CustomerServiceOrderIdSpecification spec = new CustomerServiceOrderIdSpecification(TestConstants.Instance.ORDER_ID);

            //Act
            IEnumerable<CustomerService> customerService = repository.FindCustomerServices(spec);

            //Assert
            Assert.IsNotNull(customerService);
        }

        #endregion
    }
}
